﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.peddlerUI.peddlerMarketUI {
    import Engine.Managers.*;
    import Events.*;
    import Display.DialogUI.*;
    import Transactions.*;
    import Display.*;
    import Display.CopsBanditsUI.*;
    import org.aswing.event.*;
    import Display.peddlerUI.peddlerMarketUI.data.*;
    import Display.peddlerUI.peddlerMarketUI.list.*;
    import Display.peddlerUI.peddlerMarketUI.factory.*;

    public class PeddlersPanel extends OfficersPanel {

        private var m_peddlers:PeddlerListPanel;

        public static function askDonuts():void{
            var _local1:String = ZLoc.t("Dialogs", "peddlercenter_askDonuts");
            var _local2:GenericDialog = new GenericDialog(_local1, "", GenericDialogView.TYPE_CUSTOM_OK, sendDonutsFeedHandle, "", "", true, 0, "", null, ZLoc.t("Dialogs", "PeddlerCenter_button_getdonuts"));
            UI.displayPopup(_local2);
        }
        private static function sendDonutsFeedHandle(_arg1:GenericPopupEvent):void{
            var _local2:Boolean;
            if (_arg1.button == GenericDialogView.YES){
                _local2 = Global.world.viralMgr.sendGetDonutForPeddlerCenter();
                if (!_local2){
                    UI.displayMessage(ZLoc.t("Dialogs", "PeddlerCenter_feedMax"), GenericDialogView.TYPE_OK);
                    StatsManager.count("peddlercenter", "askdonuts", "request_limit_ui");
                } else {
                    StatsManager.count("peddlercenter", "askdonuts", "send_feed");
                };
            } else {
                StatsManager.count("peddlercenter", "askdonuts", "X");
            };
        }

        override protected function createListContent():void{
            m_officers = new PeddlerListPanel(new PeddlerCellFactory(), Global.peddlerManager.peddlers);
        }
        public function refreshData(_arg1:Array=null):void{
            if (m_officers){
                _arg1 = ((_arg1 == null)) ? Global.peddlerManager.peddlers : _arg1;
                (m_officers as PeddlerListPanel).updataAllCells(_arg1);
            };
        }
        override protected function setlocalizationforAllComponents():void{
            var _local1:int = Global.gameSettings.getInt("PeddlerCenterdonutCashCost");
            var _local2:String = ZLoc.t("Dialogs", "BuyDonatsForPeddler", {money:_local1});
            m_buyButton.setText(_local2);
            _local2 = ZLoc.t("Dialogs", "PeddlerCenter_button_getdonuts");
            m_getDonutsButton.setText(_local2);
        }
        override protected function judgeButtonEnable():void{
            var _local1:PeddlerData = Global.peddlerManager.findDonutHungryPeddler();
            if (_local1){
                m_buyButton.setEnabled(true);
                m_getDonutsButton.setEnabled(true);
            } else {
                m_buyButton.setEnabled(false);
                m_getDonutsButton.setEnabled(false);
            };
        }
        override protected function buyDonuts(_arg1:AWEvent):void{
            var _local3:int;
            var _local4:TBuyDonutForPeddler;
            StatsManager.count("peddlercenter", "askdonuts", "buydonuts");
            var _local2:PeddlerData = Global.peddlerManager.findDonutHungryPeddler();
            if (_local2 != null){
                _local3 = Global.gameSettings.getInt("PeddlerCenterdonutCashCost");
                if (Global.player.cash >= _local3){
                    _local4 = new TBuyDonutForPeddler(_local2.peddlerId);
                    TransactionManager.addTransaction(_local4, true);
                    StatsManager.count("peddlercenter", "askdonuts", "buy_success");
                    Global.player.cash = (Global.player.cash - _local3);
                    _local2 = Global.peddlerManager.wakeUpPeddlerData(_local2);
                    (m_officers as PeddlerListPanel).updateCellData(_local2);
                    Global.peddlerManager.reflashPeddlerCenterStatue();
                    this.judgeButtonEnable();
                } else {
                    UI.displayPopup(new GetCoinsDialog(ZLoc.t("Dialogs", "ImpulseMarketCash"), "GetCash", GenericDialogView.TYPE_GETCASH, null, true));
                };
            };
        }
        override protected function sendDonutsFeed(_arg1:AWEvent):void{
            askDonuts();
        }

    }
}//package Display.peddlerUI.peddlerMarketUI 
